package cn.iocoder.yudao.hires.controller.admin.notice;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.hires.entity.NoticeOfferDO;
import cn.iocoder.yudao.hires.service.notice.NoticeOfferService;
import cn.iocoder.yudao.hires.vo.noticeoffer.NoticeOfferPageReqVO;
import cn.iocoder.yudao.hires.vo.noticeoffer.NoticeOfferRespVO;
import cn.iocoder.yudao.hires.vo.noticeoffer.NoticeOfferSaveReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 下游-Offer通知")
@RestController
@RequestMapping("/system/notice-offer")
@Validated
public class NoticeOfferController {

    @Resource
    private NoticeOfferService noticeOfferService;

    @PostMapping("/create")
    @Operation(summary = "创建下游-Offer通知")
    //@PreAuthorize("@ss.hasPermission('system:notice-offer:create')")
    public CommonResult<Long> createNoticeOffer(@Valid @RequestBody NoticeOfferSaveReqVO createReqVO) {
        return success(noticeOfferService.createNoticeOffer(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新下游-Offer通知")
    //@PreAuthorize("@ss.hasPermission('system:notice-offer:update')")
    public CommonResult<Boolean> updateNoticeOffer(@Valid @RequestBody NoticeOfferSaveReqVO updateReqVO) {
        noticeOfferService.updateNoticeOffer(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除下游-Offer通知")
    @Parameter(name = "id", description = "编号", required = true)
    //@PreAuthorize("@ss.hasPermission('system:notice-offer:delete')")
    public CommonResult<Boolean> deleteNoticeOffer(@RequestParam("id") Long id) {
        noticeOfferService.deleteNoticeOffer(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得下游-Offer通知")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    //@PreAuthorize("@ss.hasPermission('system:notice-offer:query')")
    public CommonResult<NoticeOfferRespVO> getNoticeOffer(@RequestParam("id") Long id) {
        NoticeOfferDO noticeOffer = noticeOfferService.getNoticeOffer(id);
        return success(BeanUtils.toBean(noticeOffer, NoticeOfferRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得下游-Offer通知分页")
    //@PreAuthorize("@ss.hasPermission('system:notice-offer:query')")
    public CommonResult<PageResult<NoticeOfferRespVO>> getNoticeOfferPage(@Valid NoticeOfferPageReqVO pageReqVO) {
        PageResult<NoticeOfferDO> pageResult = noticeOfferService.getNoticeOfferPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, NoticeOfferRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出下游-Offer通知 Excel")
    //@PreAuthorize("@ss.hasPermission('system:notice-offer:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportNoticeOfferExcel(@Valid NoticeOfferPageReqVO pageReqVO, HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<NoticeOfferDO> list = noticeOfferService.getNoticeOfferPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "下游-Offer通知.xls", "数据", NoticeOfferRespVO.class, BeanUtils.toBean(list, NoticeOfferRespVO.class));
    }

}